Skip to content

AI keys: the key that started a request shows an X, tapping it cancels - #890

Open
4di-hello wants to merge 1 commit into
LeanBitLab:mainfrom
4di-hello:feature/ai-key-cancel
Open

4di-hello wants to merge 1 commit into
LeanBitLab:mainfrom
4di-hello:feature/ai-key-cancel

Conversation

@4di-hello

@4di-hello 4di-hello commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

While an AI request runs, only the proofread key turned into an X, also when the request came from the translate key or a custom AI key.

  • The key that started the request now shows the X, and gets its own icon back afterwards. The key is passed along with the request, so a request that doesn't start leaves nothing behind.
  • A tap on the translate key or a custom AI key while any AI request runs cancels it (also a request started by another AI key), like the proofread key already did, with a short "AI request cancelled" message.

This fits well with #889: as custom key requests keep running when the keyboard hides, there should be a clear way to stop one.

🤖 Generated with Claude Code

@LeanBitLab LeanBitLab left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, showing the X on the key that started the request makes sense. One bug before we can merge:

The X can end up on the wrong key
nextLoadingKey is a global that is set in handleTranslate / handleCustomAIKey before translateAsync / customAsync, but it is only cleared in showLoadingAnimation. In several cases the loading animation never starts, so the value stays set:

  • performAsyncOperation returns early without showing the animation: no text, no model selected (offline), no API key (standard),
  • showLoadingAnimation itself returns early when the strip is not attached or not visible (SuggestionStripView.kt, the isAttachedToWindow / visibility check), e.g. when the toolbar is hidden.

Example: tap translate in an empty field ("No text" toast, nextLoadingKey = TRANSLATE stays), then tap proofread in a field with text: the X appears on the translate key instead of proofread, and the proofread key keeps its normal icon although tapping it cancels.

Suggested fix: don't keep the key in a global between the two calls. For example, pass the key along with the request (ProofreadHelper already posts showLoadingAnimation(), it could post showLoadingAnimation(key)), or at least clear nextLoadingKey in hideLoadingAnimation() and on every early return in performAsyncOperation in both flavors.

Smaller points

  • While any AI request runs, tapping a different AI key now cancels the running request instead of starting its own (e.g. translate during a proofread). That is fine with me, but please mention it in the description.
  • If the toolbar is rebuilt while a request runs, loadingKeyIcons holds the old buttons, so the restore in hideLoadingAnimation() goes to views that are no longer shown. Harmless, but finding the buttons by tag again on restore (like the old code) would avoid it.
  • Please use imports instead of the fully qualified helium314.keyboard.latin.suggestions.nextLoadingKey / ToolbarKey names in InputLogic.

@LeanBitLab LeanBitLab left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as changes requested: please fix the stale nextLoadingKey described in my review comment above (the X can end up on the wrong key after a request that never started).

While an AI request runs, only the proofread key turned into an X, also when
the request came from the translate key or a custom AI key. Now the key that
started the request shows the X and gets its own icon back afterwards. The
key is passed along with the request (ProofreadHelper -> showLoadingAnimation),
so a request that doesn't start (no text, no model, no API key, toolbar not
shown) leaves nothing behind. Buttons are looked up again on restore, in case
the toolbar was rebuilt meanwhile.

A tap on the translate key or a custom AI key while any AI request runs
cancels it, like the proofread key already did, with a short message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VuiaMhLXwhErf9shhrr1uD
@4di-hello
4di-hello force-pushed the feature/ai-key-cancel branch from 4121ed9 to fc3ea63 Compare November 22, 2026 10:42
@4di-hello

Copy link
Copy Markdown
Contributor Author

Thanks, good catch! Fixed in the updated branch (one commit, force-pushed, now on current main with #888):

  • No global anymore: the key is passed along with the request. translateAsync uses TRANSLATE, customAsync gets a toolbarKey parameter, and performAsyncOperation posts showLoadingAnimation(loadingKey) in both flavors. A request that returns early (no text, no model, no API key) leaves nothing behind, and loadingKey in the strip is only set after the attached/visible check and cleared in hideLoadingAnimation().
  • On restore, the buttons are looked up by tag again; a button created by a toolbar rebuild already has its own icon and is left alone.
  • Imports instead of the fully qualified names in InputLogic.
  • Description updated: while any AI request runs, a tap on another AI key cancels it instead of starting its own request.

It still merges cleanly together with #889, and the unit tests pass in both flavors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants